﻿<link href="<?php echo base_url()?>common/css/public.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="<?php echo base_url()?>common/kindeditor/themes/default/default.css" />
<script type="text/javascript" src="<?php echo base_url()?>common/js/jquery.min.js"></script>
<script type="text/javascript" src="<?php echo base_url()?>common/layer/layer.js"></script>
<script type="text/javascript">
    $(function () {
        $("input:checkbox").click(function () {
            var $this = $(this);
            if ($(this).prop("checked")) {               
                add_goods_color($(this).val());
            }
            else {
                layer.confirm("取消该颜色，将删除改色值对应的所有商品库存，确定执行该操作？", function (index) {
                    del_goods_color($this.val());
                    layer.close(index);
                }, function () {
                    $this.prop("checked", "checked");
                    layer.msg('取消删除', { icon: 0 });
                })
            }
        });
    });
    function Success(data) {
        parent.Success(data);

    }
    function add_goods_color(color_id) {
        var url = "/admin/goods/addgoods_color";
        var goods_id="<?php echo $goodsid?>";
        $.post(url, { "colorid": color_id, "goodsid": goods_id }, function (data) {
            var jsonData = $.parseJSON(data);
            if (jsonData.Statu == 'ok') {
                Success(jsonData)
            }
            else {
                Success(jsonData)
            }
        })
    }

    function del_goods_color(color_id) {
        var url = "/admin/goods/delgoods_color";
        var goods_id="<?php echo $goodsid?>";
        $.post(url, { "colorid": color_id, "goodsid": goods_id }, function (data) {
            var jsonData = $.parseJSON(data);
            if (jsonData.Statu == 'ok') {
                Success(jsonData)
            }
            else {
                Success(jsonData)
            }
        })
    }

</script>
<div id="dcMain" style="margin-left:0;padding-top:10px;">
    <div style="padding-left:22px;color:red;">注：选择即修改</div>
    <!-- 当前位置 -->
    <div id="manager" class="mainBox" style="padding-top:0;">
        <table width="100%" border="0" cellpadding="8" cellspacing="0" class="tableBasic">
            <tr>
                <th width="35">选择</th>
                <th>颜色描述</th>
                <th>样式</th>
            </tr>
            <?php foreach($goodscolorlist as $goodscolorItem):?>
            <tr>
                <td width="30" align="center"> <input ck="ck" id="color_<?php echo $goodscolorItem['colorid']?>" type="checkbox" <?php echo $goodscolorItem['goods_color_id']>0?"checked='checked'":""?> value="<?php echo $goodscolorItem['colorid']?>" /></td>
                <td>
                    <label style="width:100%;height:100%;display:block;" for="color_<?php echo $goodscolorItem['colorid']?>"><?php echo $goodscolorItem['title']?></label>
                </td>
                <td><label style="width:100%;height:100%;display:block;" for="color_<?php echo $goodscolorItem['colorid']?>"><span style="display:block;height:40px;width:40px;"><img  style="width:35px;" src="<?php echo $goodscolorItem['colorkey'];?>" /></span></label> </td>
            </tr>
            <?php endforeach;?>
        </table>
    </div>
</div>
